package com.ccntec.spark.core.tags.form.input;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.ccntec.spark.core.util.StringUtil;

public class InputTag extends TagSupport {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 186838176553402736L;
	private String name ;//表单属性值
	private String id ;//表单ID
	private String type ;//类型
	private String style ;//风格
	private String width ; //表单宽
	private String hight; //高
	private String defaultValue ; //默认值
	private String buttonTxt; //带按钮的文本框
	private String butOnclick; //按钮点击时间

	private boolean readOnly ; //只读
	private boolean disabled ; //不可用
	private boolean required;
	
	
	@Override
	public int doStartTag() throws JspException {
		StringBuffer html = new StringBuffer();
		if(disabled){
			html.append("<fieldset disabled=\"\">");
		}
		html.append("<div class=\"form-group\">");
		html.append("<div class=\"input-group\">");
		if(StringUtil.isNull(style)){
			html.append("<input class=\"form-control\" ");
		}else{
			html.append("<input class=\""+style+"\" ");
		}
		html.append("name=\""+name+"\" ");
		if(!StringUtil.isNull(id)){
			html.append("id=\""+id+"\" ");
		}
		if(!StringUtil.isNull(type)){
			html.append("type=\""+type+"\" ");
		}else{
			html.append("type=\"text\" ");
		}
		if(!StringUtil.isNull(defaultValue)){
			html.append("placeholder=\""+defaultValue+"\" ");
		}
		if(readOnly){
			html.append("readOnly=\""+readOnly+"\" ");
		}
		if(!StringUtil.isNull(hight)){
			html.append("hight=\""+hight+"\" ");
		}
		if(!StringUtil.isNull(width)){
			html.append("width=\""+width+"\" ");
		}
		html.append(" >");
		if(!StringUtil.isNull(buttonTxt)){
			html.append("<span class=\"input-group-btn\">");
			html.append("<button class=\"btn btn-default\" type=\"button\" ");
			if(!StringUtil.isNull(butOnclick)){
				 html.append("onclick=\"javascript:"+butOnclick+"\"");
			}
			html.append(">");
			html.append(buttonTxt);
			html.append("</button></span>");
		}
		
		html.append("</input>");
		html.append("</div></div>");
		if(disabled){
			html.append("</fieldset>");
		}
		try {
			pageContext.getOut().print(html);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}
	
	@Override
	public int doEndTag() throws JspException {
		return EVAL_PAGE;
	}
	
	@Override
	public void release() {
		// TODO Auto-generated method stub
		super.release();
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public void setHight(String hight) {
		this.hight = hight;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public void setReadOnly(boolean readOnly) {
		this.readOnly = readOnly;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setRequired(boolean required) {
		this.required = required;
	}
	public void setType(String type) {
		this.type = type;
	}

	public void setButtonTxt(String buttonTxt) {
		this.buttonTxt = buttonTxt;
	}
	public void setButOnclick(String butOnclick) {
		this.butOnclick = butOnclick;
	}
	
}
